package symbol;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;

import xyz.SimpleNode;

public class Env extends Symbol {
	protected Hashtable<String, Symbol> table;

	public Env(Symbol p, String name, SimpleNode node) {
		super(p, name, node);
		table = new Hashtable<String, Symbol>();
		prev = p;
	}

	public void putInCurrEnv(String s, Symbol sym) {
		table.put(s, sym);
	}

	public Symbol getInCurrEnv(String s) {
		return table.get(s);
	}

	public Hashtable<String, Symbol> getTable() {
		return table;
	}

	public void setTable(Hashtable<String, Symbol> table) {
		this.table = table;
	}

	@Override
	public String toString() {
		String s = "env:" + getName() + "\nprev:";
		if (getPrev() == null)
			s += "null\n";
		else
			s += getPrev().getName() + "\n";
		Set<String> keySet = table.keySet();
		Iterator<String> i = keySet.iterator();
		while (i.hasNext()) {
			String key = i.next();
			Symbol e = table.get(key);
			s = s + "containedEnv:" + e.getName() + "\n";
		}
		return s;
	}

	public void dump() {
		System.out.print("\n" + toString());
		Set<String> s = table.keySet();
		Iterator<String> i = s.iterator();
		while (i.hasNext()) {
			String key = i.next();
			Symbol e = table.get(key);
			e.dump();
		}
		// List<Symbol> list = (List<Symbol>)table.values();
		// for(int i = 0; i < list.size(); i++){
		// Env e = (Env)list.get(i);
		// e.dump();
		// }
	}

}
